/**
 * geoportal-settings.js
 * This file contains global settings that will vary by implementation,
 * i.e. map extent, projection, layers, etc.
 * Created by Mike Wilson
 * 8/25/10
 * @license     MIT
 */


/**
 * Globals
 * General global variables should go here unless they're part of a module.  
 */
var wsbase = "http://maps.co.mecklenburg.nc.us/rest/";   // Base URL for REST web services
var map = null;  // Openlayers map
var markerLayer = null;  // Layer for vector markers
var selectControl = null;  // OpenLayers select control for vector marker layer
var selectedAddress = null;
var mapControls = null;
var innerLayout, middleLayout = null;


/**
 * Fix for OpenLayers using 900913 for web mercator and AGS using 102113
 * Specify projection for AGS as 102113 and it will substitute that rather
 * than use 900913 for those requests.
 * Must run before map init
 */ 
OpenLayers.Layer.WMS.prototype.getFullRequestString = function(newParams,altUrl)
{
    try{
        var projectionCode=typeof this.options.projection == 'undefined' ? this.map.getProjection() : this.options.projection;
    }catch(err){
        var projectionCode=this.map.getProjection();
    }
    this.params.SRS = projectionCode=="none" ? null : projectionCode;
    return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(this,arguments);
}


/**
 * General OpenLayers settings
 */
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 4;  // Avoid pink tiles
var defaultMapExtent = new OpenLayers.Bounds(-9024575.71780708, 4163697.68596957, -8966390.6897618, 4234743.17441856);
var mapOptions = {
		projection: new OpenLayers.Projection("EPSG:900913"),
		displayProjection: new OpenLayers.Projection("EPSG:4326"),
		units: "m",
		numZoomLevels: 18,
		maxResolution: 156543.0339,
		maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34),
		restrictedExtent: defaultMapExtent,
		controls: [new OpenLayers.Control.MouseDefaults()],
		fallThrough: false
};



/**
 * Function to add map layers
 */
function AddMapLayers() {
  	map.addLayers(
     	[
         	meckbaselayer, 
			osmarender, 
			environmental_layer, 
			nexrad
       	]
	);
}
	
		
/**
 * Map Layers 
 */
// Mecklenburg County Base Layer
meckbaselayer = new OpenLayers.Layer.WMS( "Mecklenburg GIS Base Map", 
	"http://maps.co.mecklenburg.nc.us/geoserver/gwc/service/wms", {layers: 'meckbase', format: 'image/png'},
	{ minScale: 866688.0326643361, maxScale: 846.3750318987657 ,  'attribution': 'Provided by <a href="http://emaps.charmeck.org/">Mecklenburg County GIS</a>', 'displayInLayerSwitcher':true, 'transitionEffect': 'resize'});
// OpenStreetMap Base Layer
osmarender = new OpenLayers.Layer.OSM(
	"OpenStreetMap (Tiles@Home)",
	"http://tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png"
);
// Environmental Overlay Layer
environmental_layer = new OpenLayers.Layer.WMS( "Environmental Layers", 
	"http://maps.co.mecklenburg.nc.us/geoserver/wms", {
	layers: 'postgis:view_regulated_floodplains,postgis:landfills,postgis:mpl_sites,postgis:water_quality_buffers,postgis:proposed_thoroughfares,postgis:soil,postgis:air_pollution_facilities', 
	format: 'image/gif', transparent: 'true'}, 
	{isBaseLayer: false, minScale: 8000, maxScale: 100, buffer:0, singleTile: true, opacity: 0.7, visibility: false});
// Weather Radar Overlay Layer
nexrad = new OpenLayers.Layer.WMS(
    "Nexrad Weather Radar",
    "http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?",
    {layers:"nexrad-n0r", transparent: "TRUE", format: 'image/png'},
    {isBaseLayer: false, buffer:0, singleTile: false, opacity: 0.5, visibility: false}
);